/*
 * JGO2RDF creates a RDF representation of GAF2 files, which are automatically sourced from GO ftp site.
 * Copyright (C) 2012 Matthew M. Hindle & Artem Lysenko
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package uk.co.jgo2rdf.goa;

import uk.co.jgo2rdf.goa.parser.GOAIndexer;

import java.io.*;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.zip.GZIPInputStream;

/**
 * Created by IntelliJ IDEA.
 * User: mhindle
 * Date: 04/02/12
 * Time: 18:24
 * To change this template use File | Settings | File Templates.
 */
public class CreateGOAIndecies {


    public static void main(String[] args) throws IOException, GOAIndexer.InvalidGOAFileException, IllegalAccessException, InstantiationException {
        File dir = new File(args[0]);
        File[] files = dir.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".gz");
            }
        });

        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");

        for (File file : files) {
            System.out.println(file);

            String indexName = dir.getAbsolutePath()
                    + File.separator + file.getName().substring(0, file.getName().lastIndexOf('.')) + "-index";

            if (new File(indexName).exists())
                continue;

            InputStream fis = new BufferedInputStream(
                    new GZIPInputStream(new FileInputStream(file)));
            GOAIndexer index = new GOAIndexer(fis, df,
                    Charset.forName("UTF8"),
                    indexName);
            System.out.println(index.getAllEntries().size());

        }
    }

}
